import 'dart:async';
import 'package:flutter/material.dart';
import 'package:xlsk/components/search.dart';
import 'package:xlsk/components/tabs.dart';
import 'package:xlsk/utils/dimension.dart';

class My extends StatefulWidget {
  num height = 0;
  bool showContent = false;
  bool showOffstage = true; // true为隐藏
  double opacity = 0;

  @override
  State<StatefulWidget> createState() {
    return _indexState();
  }
}

class _indexState extends State<My> {
  late OverlayEntry overlayEntry;
  late var overlayState;

  @override
  void initState() {
    super.initState();
    overlayState = Overlay.of(context);
    overlayEntry = new OverlayEntry(
        builder: (context){
          return Align(
            alignment: Alignment.topCenter,
            child: Container(height: 200, width: 200, color: Colors.blue.withOpacity(0.4)),
          );
        }
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("My"),
      ),
      body: Column(
        children: [
          Container(
            child: Search(343,32,'搜索学员姓名',(value){
              print("value");print(value);
            }),
            width: Dimension(context).toVw(100),
            padding: EdgeInsets.symmetric(vertical: Dimension(context).toPx(8),horizontal: Dimension(context).toPx(16)),
            decoration: BoxDecoration(
                color: Colors.white
            ),
          ),
          Container(
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                // Tabs(200, ['全部','在读','历史'],0),
                Container(
                  child: GestureDetector(
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Text('筛选',style: TextStyle(color: Color(0xff1f2329),fontSize: Dimension(context).toPx(14))),
                        Image.asset('assets/images/student-filter.png',width: Dimension(context).toPx(16),height: Dimension(context).toPx(16)),
                      ],
                    ),
                    onTap: (){

                      // overlayEntry.remove();
                      overlayState?.insert(overlayEntry);
                      setState(() {

                      });
                    },
                  ),
                  width: Dimension(context).toPx(50),
                  height: Dimension(context).toPx(40),
                ),
              ],
            ),
            width: Dimension(context).toVw(100),
            height: Dimension(context).toPx(48),
            padding: EdgeInsets.only(bottom: Dimension(context).toPx(8),right: Dimension(context).toPx(18)),
            decoration: BoxDecoration(
              color: Colors.white
            ),
          ),
          // Stack(
          //     children: [
          //     Stack(
          //       children: [
          //         Positioned(
          //           child: Container(
          //             child:GestureDetector(
          //               child: Row(
          //                 mainAxisAlignment: MainAxisAlignment.spaceBetween,
          //                 children: [
          //                   Text('筛选',style: TextStyle(color: Color(0xff1f2329),fontSize: Dimension(context).toPx(14))),
          //                   Image.asset('assets/images/student-filter.png',width: Dimension(context).toPx(16),height: Dimension(context).toPx(16)),
          //                 ],
          //               ),
          //               onTap: (){
          //                 setState(() {
          //                   if(widget.showContent){
          //                     Timer(Duration(milliseconds: 300),(){
          //                       widget.showOffstage = true;
          //                     });
          //                   }else{
          //                     widget.showOffstage = false;
          //                   }
          //                   widget.height = widget.showContent?0:230;
          //                   widget.opacity = widget.showContent?0:0.3;
          //                   widget.showContent = !widget.showContent;
          //                 });
          //               },
          //               behavior: HitTestBehavior.opaque,
          //             ),
          //             width: Dimension(context).toPx(50),
          //             height: Dimension(context).toPx(40),
          //           ),
          //           top: 0,
          //           right: Dimension(context).toPx(18),
          //         ),
          //         GestureDetector(
          //           child: Offstage(
          //             offstage: widget.showOffstage,
          //             child: AnimatedContainer(
          //               decoration: BoxDecoration(
          //                 color: Color.fromRGBO(0, 0, 0, widget.opacity),
          //                 // color: Colors.red
          //               ),
          //               width: Dimension(context).toVw(100),
          //               height: Dimension(context).toVh(100),
          //               duration: Duration(milliseconds: 300),
          //               margin: EdgeInsets.only(top: Dimension(context).toPx(40)),
          //             ),
          //           ),
          //           onTap: (){
          //             setState(() {
          //               widget.height = 0;
          //               widget.opacity = 0;
          //               widget.showContent = false;
          //             });
          //           },
          //         ),
          //         Positioned(
          //           child: Offstage(
          //             offstage: widget.showOffstage,
          //             child: AnimatedContainer(
          //               child: GestureDetector(
          //                 child: Text('点击'),
          //                 onTap: (){
          //                   print('ddd');
          //                 },
          //               ),
          //               decoration: BoxDecoration(
          //                   color: Colors.white
          //               ),
          //               width: Dimension(context).toVw(100),
          //               height: Dimension(context).toPx(widget.height),
          //               duration: Duration(milliseconds: 300),
          //               curve: Curves.fastOutSlowIn,
          //             ),
          //           ),
          //           left: 0,
          //           top: Dimension(context).toPx(40),
          //         ),
          //       ],
          //       clipBehavior: Clip.none,
          //     ),
          //     Positioned(
          //       child: Tabs(200, ['全部','在读','历史'],0),
          //       left: 0,
          //       top: 0,
          //     )
          //   ],
          //   clipBehavior: Clip.none,
          // ),
        ],
      ),
    );
  }
  @override
  void dispose() {
    super.dispose();
    overlayEntry.remove();
  }
}

